//
//  FeetView.m
//  NewGame
//
//  Created by wwj on 15/10/13.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "FeetView.h"
@interface FeetView ()

@property (weak ,nonatomic) IBOutlet UIImageView *imageView;
@property (weak ,nonatomic) IBOutlet NSLayoutConstraint *margeX;
@end

@implementation FeetView

-(void)awakeFromNib{
    _imageView.animationImages = @[
                                   [UIImage imageNamed:@"01-feet01.png"],
                                   [UIImage imageNamed:@"01-feet02.png"],
                                   [UIImage imageNamed:@"01-feet02.png"],
                                   [UIImage imageNamed:@"01-feet03.png"]
                                   ];
    _imageView.animationRepeatCount = 2;
}

-(void)begin{
    self.hidden = NO;
}

-(void)random{
    [_imageView stopAnimating];
    // 1.获得脚当前的索引
    int oldIndex = [self currentIndex];
    
    int index = oldIndex;
    while(index == oldIndex) {
        index = arc4random_uniform(3);
    }
    _margeX.constant = index * self.frame.size.width;
    
    
}

-(BOOL)isHitFeetWithIndex:(int)index{
    if (index == self.currentIndex) {
        [_imageView startAnimating];
        return YES;
    }
    return NO;
}

- (int)currentIndex{
    return self.frame.origin.x / self.frame.size.width;
}

@end
